# 打开摄像头
import cv2
# 引入时间对象
import datetime

if __name__ == '__main__':
    cap = cv2.VideoCapture(0)
    while True:
        fig,frame = cap.read()
        # 判断摄像头未启动
        if fig is None:
            print("Capture No Found")
            break
        key = cv2.waitKey(1)
        # 手动退出
        if key == ord(" "):
            break
        elif key == ord("s"):
            time = datetime.datetime.now()
            time = time.strftime("%H%M%S")
            # xxx.拼音名称.jpg
            cv2.imwrite(f"./train/{time}.shen.jpg",frame)
            print(f"./train/{time}.shen.jpg")
        # 按下s保存一张照片
        cv2.imshow("capture",frame)
    # 释放资源
    cap.release()
    cv2.destroyAllWindows()